<div class="layui-card">
    <div class="layui-card-header">
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>充值详情管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="recharge-details-search-key">
                <option value="">-请选择-</option>
                <option value="player_id">ID</option>
                <option value="order_id">订单号</option>
                <option value="details_time">时间</option>
            </select>
            <div class="layui-inline">
                <input type="text" class="layui-input time" id="order_time">
            </div>
            <input id="recharge-details-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="recharge-details-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>
        <table class="layui-table" id="recharge-details-table" lay-filter="recharge-details-table"></table>
    </div>
</div>

<script>
    layui.use([ 'table', 'util', 'config','form','laydate'], function () {
        var table = layui.table;
        var config = layui.config;
        var util = layui.util;
        var form = layui.form;
        var laydate = layui.laydate;

        $("#order_time").hide();
        laydate.render({
            elem: '#order_time' //指定元素
            , type: 'date'
            , format: 'yyyy-MM-dd'
            , max: 1
        });
        var cols = [[
            {type: 'numbers',rowspan:'2'},
            {field: 'playerId',rowspan:'2', title: '玩家ID'},
            {field: 'orderId',rowspan:'2', title: '订单号'},
            {field: 'money',rowspan:'2', sort: true, title: '充值金额'},
            {
                field: 'createTime',rowspan:'2', sort: true, templet: function (d) {
                    return util.toDateString(d.createTime);
                }, title: '订单时间'
            },
            {align: 'center', colspan:'2', title: '奖励'}
        ],[
            {
                field: 'rewardOne',rowspan:'2', templet: function (d) {
                    return rewardOne(d.rewardOne);
                }, title: '金币/钻石'
            },
            {
                field: 'rewardTwo',rowspan:'2', templet: function (d) {
                    return rewardTwo(d.rewardTwo);
                }, title: '宝箱钥匙'
            }
        ]];

        // 渲染表格
        table.render({
            elem: '#recharge-details-table',
            url: config.base_server + 'api-select/rechargeDetails',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            cols: cols
        });

        form.on('select', function (data) {
            if (data.value == "details_time") {
                $("#order_time").show();
                $("#recharge-details-search-value").hide();
            }
            if (data.value == "player_id" || data.value == "order_id") {
                $("#order_time").hide();
                $("#recharge-details-search-value").show();
            }
        });

        // 搜索按钮点击事件
        $('#recharge-details-btn-search').click(function () {
            var key = $('#recharge-details-search-key').val();
            var value;
            if ('details_time' == key) {
                value = $('#order_time').val();
            }else {
                value = $('#recharge-details-search-value').val();
            }
            table.reload('recharge-details-table', {where: {rechargeDetailsSearchKey: key, rechargeDetailsSearchValue: value}});
        });

        /**
         * 0:金币
         * 1:钻石
         */
        function rewardOne(data){
            if (!data){
                return 0;
            }
            var str;
            if (data.hasOwnProperty("0")){
                str = "金币:" + data[0] + ";";
            }
            if (data.hasOwnProperty("1")){
                str = str + "钻石:" + data[1];
            }
            return str;
        }
        /**
         * 0:钻石
         * 1:白银
         * 2:黄金
         * 3:活动
         * 4:工会
         */
        function rewardTwo(data){
            if (!data){
                return 0;
            }
            var str;
            if (data.hasOwnProperty("0")){
                str = "钻石:" + data[0] + ";";
            }
            if (data.hasOwnProperty("1")){
                str = str + "白银:" + data[1] + ";";
            }
            if (data.hasOwnProperty("2")){
                str = str + "黄金:" + data[2] + ";";
            }
            if (data.hasOwnProperty("3")){
                str = str + "活动:" + data[3] + ";";
            }
            if (data.hasOwnProperty("4")){
                str = str + "工会:" + data[4];
            }
            return str;
        }
    });
</script>